﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpaceGame.Gameplay;

namespace SpaceGame.Rendering
{
    /// <summary>
    /// Class is responsible for creation of simple particle effects and signalling cues 
    /// to audio manager.
    /// </summary>
    class BasicEffects : IEffectsStrategy
    {
        private readonly World world;

        #region Constants
        /// <summary>
        /// Particle system colors for the ship-explosion effect.
        /// </summary>
        static readonly Color[] explosionColors = 
            { 
                Color.Red, Color.Red, Color.Silver, Color.Gray, Color.Orange, 
                Color.Yellow 
            };
        #endregion

        #region Initialization
        /// <summary>
        /// Creates instance responsible for effects in this world.
        /// </summary>
        /// <param name="world">who doesn't need it</param>
        public BasicEffects(World world)
        {
            this.world = world;
        }
        #endregion
        
        /// <summary>
        /// Add particles with ship's color.
        /// </summary>
        /// <param name="ship"></param>
        public void ShipSpawned(Ship ship)
        {
            world.ParticleSystems.Add(new ParticleSystem(ship.Position, 
                Vector2.Zero, 32, 32f, 64f, 2f, 0.1f, ship.Color));
        }

        /// <summary>
        /// Simiulate explosition with particles.
        /// </summary>
        /// <param name="ship"></param>
        public void ShipDies(Ship ship)
        {
            world.ParticleSystems.Add(new ParticleSystem(ship.Position, Vector2.Zero, 128, 64f, 256f, 3f, 0.05f, explosionColors));
            world.ParticleSystems.Add(new ParticleSystem(ship.Position, Vector2.Zero, 64, 256f, 1024f, 3f, 0.05f, explosionColors));
        }
    }
}
